<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>


    <div class="top">
        <img src="../images/girlbig1.jpg" alt="">
    </div>
    <p>
        <img src="../images/girlsmall1.jpg" alt="">
        <img src="../images/girlsmall2.jpg" alt="">
        <img src="../images/girlsmall3.jpg" alt="">
        <img src="../images/girlsmall4.jpg" alt="">

    </p>


    <script>


        var s = ['../images/girlsmall1.jpg', '../images/girlsmall2.jpg'];
        var b = ['../images/girlbig1.jpg', '../images/girlbig2.jpg'];



        var oImgs = document.querySelectorAll('p img');
        var oTop = document.querySelector('.top img');

        // for (var i = 0; i < oImgs.length; i++) {
        //     oImgs[i].index = i + 1;
        //     oImgs[i].onmouseover = function () {
        //         // oTop.src = this.src;  如果直接用同一张图片，图片小了会失真，大了影响页面的加载速度
        //         oTop.src = `../images/girlbig${this.index}.jpg`
        //     }
        // }


        for (var i = 0; i < oImgs.length; i++) {
            // 对象的自定义属性
            oImgs[i].index = i;
            oImgs[i].onmouseover = function () {
                // 切换路径即可
                oTop.src = b[this.index];
            }
        }

    </script>

</body>

</html>